package cn.laixueit.controller;

import cn.laixueit.pojo.SpecGroup;
import cn.laixueit.pojo.SpecParam;
import cn.laixueit.service.SpecGroupService;
import cn.laixueit.service.SpecParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class SpecController {

    @Autowired
    private SpecGroupService specGroupService;

    @Autowired
    private SpecParamService specParamService;


    @GetMapping("/spec/groups/{cid}")
    public ResponseEntity<List<SpecGroup>> groupsByCid(@PathVariable("cid")Long cid){
        List<SpecGroup> specGroupList = specGroupService.groupsByCid(cid);
        return ResponseEntity.ok(specGroupList);
    }

    @GetMapping("/spec/params")
    public @ResponseBody List<SpecParam> specParamsByGid(@RequestParam(value = "gid",required = false)Long gid,
                                                         @RequestParam(value = "cid",required = false)Long cid,
                                                         @RequestParam(required = false)Boolean searching,
                                                         @RequestParam(required = false)Boolean generic){
         List<SpecParam> specParamList =  specParamService.specParamsByGid(gid,cid,searching,generic);
         return specParamList;
    }

}
